package com.yic.module.mes.api.process;

import cn.hutool.core.util.ObjectUtil;
import com.yic.module.base.api.factory.FactoryApi;
import com.yic.module.base.api.factory.dto.FactoryRespDTO;
import com.yic.module.mes.api.process.dto.ProcessRespDTO;
import com.yic.module.mes.convert.process.ProcessConvert;
import com.yic.module.mes.dal.dataobject.process.ProcessDO;
import com.yic.module.mes.service.process.ProcessService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Ljx
 * @createTime: 2023年12月04日 13:35:56
 * @version: v1.0.0
 * @Description: 工艺API实现
 */
@Service
public class ProcessApiImpl implements ProcessApi{

    @Resource
    private ProcessService processService;
    @Resource
    private FactoryApi factoryApi;

    @Override
    public ProcessRespDTO getProcess(Long id) {
        if (ObjectUtil.isNull(id)) {
            return null;
        }
        ProcessDO process = processService.getProcess(id);
        ProcessRespDTO processRespDTO = ProcessConvert.INSTANCE.convert01(process);
        if (ObjectUtil.isNotEmpty(processRespDTO)) {
            FactoryRespDTO factory = factoryApi.getFactory(processRespDTO.getFactoryId());
            if (ObjectUtil.isNotEmpty(factory)) {
                processRespDTO.setFactoryName(factory.getName());
            }
        }
        return processRespDTO;
    }
}
